Skip to content

fix(details): match book tab keys case-insensitively - #2962

Open
posthog[bot] wants to merge 7 commits into
mainfrom
posthog-self-driving/fixdetails-match-book-tabs-case-975ff5
Open

fix(details): match book tab keys case-insensitively#2962
posthog[bot] wants to merge 7 commits into
mainfrom
posthog-self-driving/fixdetails-match-book-tabs-case-975ff5

Conversation

@posthog

@posthog posthog Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Problem

  • Educators deep-linking to instructor resources land on the wrong tab, and the URL parameter gets stuck. This is the normal entry path, not an edge case: over 30 days, nearly all instructor-resource deep links to /details/books/ arrive as the lower-case form, against a tiny fraction in any other form.
  • findSelectedTab (src/app/pages/details/common/tab-utils.ts) reads the search keys with URLSearchParams — which decodes %20 but keeps case — then matches them against the capitalized labels in src/app/lang/en.js with case-sensitive equality. Real links arrive as ?instructor%20resources in lower case, so the match fails and the page falls back to labels[0], Book details.
  • replaceSearchTerm has the same asymmetry: its lookup misses the lower-case key, so it adds a second key instead of replacing the old one. The stale instructor resources key survives and the URL becomes ?Student%20resources&instructor resources.
  • Because that function encoded only the new value, its output never equals the browser-normalized window.location.search, so the redundant-replace guard in desktop-view.tsx can never match and fires a history write on every tab click.
  • Both desktop and phone views call findSelectedTab, so the whole details-page tab system is affected.

Changes

Function Before After
findSelectedTab exact, case-sensitive key/label match case-insensitive match
replaceSearchTerm lookup misses lower-case key → adds stale key; encodes only new value case-insensitive lookup → replaces key; encodes every key
useVariant, getLinks search.includes('Instructor') case-sensitive → degraded copy/links lower-cased check
  • The encoding change makes both functions agree, so the desktop-view.tsx guard matches and the repeated history writes stop.

Scope

Test plan

  • Added unit tests in test/src/pages/details/common/tab-utils.test.ts covering the lower-case deep link, the case-mismatched replace, and the fallback.
  • yarn test and yarn lint (run in CI — the private @openstax npm registry is not reachable from the authoring environment).

Created with PostHog Desktop from this inbox report.

posthog Bot and others added 2 commits August 11, 2026 19:38
Instructor-resource deep links arrive as lower-case `?instructor%20resources`, but `findSelectedTab` compared the decoded search keys against the capitalized labels with case-sensitive equality. The match failed, so the page fell back to the Book details tab.

`replaceSearchTerm` had the same asymmetry: its lookup missed the lower-case key, so it added a second key instead of replacing the old one, leaving a stale `instructor resources` parameter in the URL. It also encoded only the new value, so the result never matched the browser-normalized `window.location.search` and the redundant-replace guard in desktop-view fired a history write on every tab click.

Compare keys against labels case-insensitively in both functions, and encode every key so the two functions agree on encoding and the guard can match.

Also lower-case the URL check in `useVariant` and `getLinks`, which degraded the dialog copy and links on the same lower-case URLs.

Generated-By: PostHog Desktop
Task-Id: be65106a-fb19-4f89-b0cd-d588022762c9
@mwvolo
mwvolo marked this pull request as ready for review August 12, 2026 16:58
@mwvolo
mwvolo requested a balanced review from Copilot August 12, 2026 16:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Makes details-page tab keys case-insensitive and normalizes their URL encoding.

Changes:

  • Matches and replaces tab keys regardless of case.
  • Updates resource variants and donation links for lowercase URLs.
  • Adds tab utility tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
tab-utils.ts Adds case-insensitive tab matching and encoding.
left-content.tsx Normalizes resource variant detection.
use-give-links.ts Normalizes donation-link selection.
tab-utils.test.ts Tests lowercase matching and replacement.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/app/pages/details/common/tab-utils.ts Outdated
Comment thread src/app/pages/details/common/resource-box/left-content.tsx Outdated
Comment thread test/src/pages/details/common/tab-utils.test.ts Outdated
Co-authored-by: mwvolo <3905516+mwvolo@users.noreply.github.com>
Copilot AI requested a review from mwvolo August 12, 2026 19:50
Co-authored-by: mwvolo <3905516+mwvolo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants